package com.memory.wechat.controller;

import com.alibaba.fastjson.JSON;
import com.memory.common.utils.ResultVoUtil;
import com.memory.common.vo.ResultVo;
import com.memory.modules.business.domain.user.IssueRecord;
import com.memory.modules.business.service.user.IssueRecordService;
import com.memory.wechat.controller.validator.param.StaffParam;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @PackageName: com.memory.wechat.controller
 * @ClassName: MessageController
 * @Description:
 * @author: zhuguangxun
 * @date 2021/3/16
 */
@Controller
@RequestMapping("message")
@RequiredArgsConstructor
public class MessageController {

    private final IssueRecordService issueRecordService;

    @GetMapping("/show")
    public String showMessage(Model model) {
        System.out.println(">>>>>");
        return "/message/msg";
    }

    @PostMapping("send")
    @ResponseBody
    public ResultVo<Boolean> sendMessage(String openId, String message) {
        return issueRecordService.create(openId, message).map(e -> ResultVoUtil.<Boolean>success("提交成功", true))
                .orElse(ResultVoUtil.<Boolean>error("发布失败"));
    }
}
